package com.codeoss.framework.view.renderer;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.data.metadata.Column;
import com.codeoss.framework.data.metadata.Table;
import com.codeoss.framework.data.store.ITableStore;
import com.codeoss.framework.util.StringUtils;
import com.codeoss.framework.view.component.Component;
import com.codeoss.framework.view.component.Page;
import com.codeoss.framework.view.component.chart.AbstractChart;
import com.codeoss.framework.view.component.chart.ChartDataItemDef;
import com.codeoss.framework.view.datasource.DataSourceConfig;
import com.codeoss.framework.view.model.SelectItem;
import com.codeoss.framework.view.util.LookupUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class AbstractChartRenderer extends CommonComponentRenderer{
	@Autowired
	private ObjectMapper objectMapper;
	@Autowired
	private ITableStore tableStore;
	@Autowired
	private LookupUtil lookupUtil;
	protected ObjectNode getRenderValue(YunContext yunContext, Component component) {
		AbstractChart abstractChart=(AbstractChart)component;
		List<ChartDataItemDef> dimensionList = abstractChart.getDimensionList();
		if (dimensionList.size() == 1) {
			return getOneDimensiongetRenderValue(yunContext, component);
		}if (dimensionList.size() == 2) {
			return getTwoDimensiongetRenderValue(yunContext, component);
		}
		return null;
	}

	protected ObjectNode getOneDimensiongetRenderValue(YunContext yunContext, Component component) {
		AbstractChart abstractChart=(AbstractChart)component;
		Page page = yunContext.getPage();
		DataSourceConfig dataSourceConfig = page.getDataSourceConfigById(abstractChart.getDataSource());
		Table table = tableStore.get(dataSourceConfig.getTableName());
		List<ChartDataItemDef> dimensionList = abstractChart.getDimensionList();
		List<ChartDataItemDef> measureList = abstractChart.getMeasureList();
		List<Map<String, Object>> mapList = yunContext.getAttribute(component.getId() + "_chartdata");
		if(mapList==null ||mapList.size()==0) {
			return null;
		}
		List<Map<String, BigDecimal>> dataMapList = new ArrayList<Map<String, BigDecimal>>();
		List<Map<String, Long>> lengthMapList = new ArrayList<Map<String, Long>>();
		for (int i = 0; i < measureList.size(); i++) {
			dataMapList.add(new HashMap<String, BigDecimal>());
			lengthMapList.add(new HashMap<String, Long>());
		}
		List<Object> dimensionValueList = new ArrayList<Object>();
		Column dimensionColumn = table.getColumnByColumnName(dimensionList.get(0).getField());
		for (int i = 0; i < mapList.size(); i++) {
			Map<String, Object> map = mapList.get(i);
			String dimensionKey = getOneDimensionKey(yunContext, abstractChart, map, dimensionValueList);
			for (int k = 0; k < measureList.size(); k++) {
				Map<String, BigDecimal> dataMap = dataMapList.get(k);
				Map<String, Long> lengthMap = lengthMapList.get(k);
				String measureField = measureList.get(k).getField();
				Object measureValue = map.get(measureField);
				String aggregateType = measureList.get(k).getAggregateType();
				BigDecimal fieldValue = dataMap.get(dimensionKey);
				if ("sum".equals(aggregateType)) {
					if (fieldValue == null) {
						fieldValue = new BigDecimal(0);
					}
					fieldValue = fieldValue.add(new BigDecimal(measureValue + ""));
					dataMap.put(dimensionKey, fieldValue);
				} else if ("average".equals(aggregateType)) {
					if (fieldValue == null) {
						fieldValue = new BigDecimal(0);
					}
					fieldValue = fieldValue.add(new BigDecimal(measureValue + ""));
					dataMap.put(dimensionKey, fieldValue);
					Long length = lengthMap.get(dimensionKey);
					if (length == null) {
						length = 1L;
					} else {
						length++;
					}
					lengthMap.put(dimensionKey, length);
				} else if ("count".equals(aggregateType)) {
					if (fieldValue == null) {
						fieldValue = new BigDecimal(0);
					}
					fieldValue = fieldValue.add(new BigDecimal(1));
					dataMap.put(dimensionKey, fieldValue);
				} else if ("min".equals(aggregateType)) {
					if (fieldValue == null) {
						dataMap.put(dimensionKey, new BigDecimal(measureValue + ""));
					} else if (new BigDecimal(measureValue + "").compareTo(fieldValue) < 0) {
						fieldValue = new BigDecimal(measureValue + "");
						dataMap.put(dimensionKey, fieldValue);
					}
				} else if ("max".equals(aggregateType)) {
					if (fieldValue == null) {
						dataMap.put(dimensionKey, new BigDecimal(measureValue + ""));
					} else if (new BigDecimal(measureValue + "").compareTo(fieldValue) > 0) {
						fieldValue = new BigDecimal(measureValue + "");
						dataMap.put(dimensionKey, fieldValue);
					}
				}
			}
		}
		for (int i = 0; i < measureList.size(); i++) {
			ChartDataItemDef chartDataItemDef = measureList.get(i);
			if (chartDataItemDef.getAggregateType().equals("average")) {
				Map<String, BigDecimal> dataMap = dataMapList.get(i);
				Map<String, Long> lengthMap = lengthMapList.get(i);
				Iterator<Map.Entry<String, BigDecimal>> it = dataMap.entrySet().iterator();
				while (it.hasNext()) {
					Map.Entry<String, BigDecimal> entry = it.next();
					long length = lengthMap.get(entry.getKey());
					if (length > 0) {
						dataMap.put(entry.getKey(), entry.getValue().divide(new BigDecimal(length)));
					}
				}
			}
		}
		List<SelectItem> selectItemList = null;
		if (dimensionColumn.getLookupInfo() != null) {
			if (dimensionColumn.getLookupInfo().getDataSourceConfig() != null) {
				Set<Object> set = new HashSet<Object>();
				set.addAll(dimensionValueList);
				selectItemList = lookupUtil.getSelectItemList(yunContext, dimensionColumn.getLookupInfo(), set);
			} else {
				selectItemList = lookupUtil.getSelectItemList(yunContext, dimensionColumn.getLookupInfo());
			}
		}
		List<String> categoryList = new ArrayList<String>();
		for (int i = 0; i < dimensionValueList.size(); i++) {
			if (selectItemList != null) {
				for (int j = 0; j < selectItemList.size(); j++) {
					if (selectItemList.get(j).getValue().equals(dimensionValueList.get(i))) {
						categoryList.add(selectItemList.get(j).getName());
					}
				}
			} else {
				categoryList.add(dimensionValueList.get(i) + "");
			}
		}
		List<Map<String, Object>> newDataList = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < categoryList.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			newDataList.add(map);
			map.put("category", categoryList.get(i));
			String dimensionKey = dimensionValueList.get(i) + "";
			for (int j = 0; j < measureList.size(); j++) {
				Map<String, BigDecimal> dataMap = dataMapList.get(j);
				BigDecimal value = dataMap.get(dimensionKey);
				map.put("value_" + j, value);
			}
		}

		String orderType = dimensionList.get(0).getOrderType();
		if (!StringUtils.isEmpty(orderType)) {
			if ("asc".equals(orderType)) {
				newDataList.sort(new Comparator<Map<String, Object>>() {
					@Override
					public int compare(Map<String, Object> o1, Map<String, Object> o2) {
						// TODO Auto-generated method stub
						String category1 = (String) o1.get("category");
						String category2 = (String) o2.get("category");
						return category1.compareTo(category2);
					}

				});
			} else if ("desc".equals(orderType)) {
				newDataList.sort(new Comparator<Map<String, Object>>() {
					@Override
					public int compare(Map<String, Object> o1, Map<String, Object> o2) {
						// TODO Auto-generated method stub
						String category1 = (String) o1.get("category");
						String category2 = (String) o2.get("category");
						return category2.compareTo(category1);
					}
				});
			}

		}

		for (int i = 0; i < measureList.size(); i++) {
			final int measureIndex = i;
			String measureOrderType = measureList.get(i).getOrderType();
			if (!StringUtils.isEmpty(measureOrderType)) {
				if ("asc".equals(measureOrderType)) {
					newDataList.sort(new Comparator<Map<String, Object>>() {
						@Override
						public int compare(Map<String, Object> o1, Map<String, Object> o2) {
							// TODO Auto-generated method stub
							BigDecimal value1 = (BigDecimal) o1.get("value_" + measureIndex);
							BigDecimal value2 = (BigDecimal) o2.get("value_" + measureIndex);
							return value1.compareTo(value2);
						}

					});
				} else if ("desc".equals(measureOrderType)) {
					newDataList.sort(new Comparator<Map<String, Object>>() {
						@Override
						public int compare(Map<String, Object> o1, Map<String, Object> o2) {
							// TODO Auto-generated method stub
							BigDecimal value1 = (BigDecimal) o1.get("value_" + measureIndex);
							BigDecimal value2 = (BigDecimal) o2.get("value_" + measureIndex);
							return value2.compareTo(value1);
						}
					});
				}

			}
		}
		int topN = abstractChart.getTopN();
		if (topN > 0 && newDataList.size() > topN) {
			int c = newDataList.size() - topN;
			for (int i = 0; i < c; i++) {
				newDataList.remove(newDataList.size() - 1);
			}
		}

		ObjectNode returnObjectNode = objectMapper.createObjectNode();
		ArrayNode categoryArrayNode = objectMapper.createArrayNode();
		for (int i = 0; i < newDataList.size(); i++) {
			categoryArrayNode.add((String) newDataList.get(i).get("category"));
		}
		returnObjectNode.set("category", categoryArrayNode);
		ArrayNode seriesArrayNode = objectMapper.createArrayNode();
		returnObjectNode.set("series", seriesArrayNode);
		for (int i = 0; i < measureList.size(); i++) {
			ObjectNode seriesObjectNode = objectMapper.createObjectNode();
			seriesArrayNode.add(seriesObjectNode);
			ChartDataItemDef chartDataItemDef = measureList.get(i);
			if (measureList.size() == 1) {
				seriesObjectNode.put("name", "默认");
			} else {
				String field = chartDataItemDef.getField();
				String name = table.getColumnByColumnName(field).getName();
				String aggregateType = chartDataItemDef.getAggregateType();
				if ("sum".equals(aggregateType)) {
					name += "_汇总";
				} else if ("average".equals(aggregateType)) {
					name += "_平均";
				} else if ("count".equals(aggregateType)) {
					name += "_数量";
				} else if ("min".equals(aggregateType)) {
					name += "_最小值";
				} else if ("max".equals(aggregateType)) {
					name += "_最大值";
				}
				seriesObjectNode.put("name", name);
			}
			ArrayNode seriesValueArrayNode = objectMapper.createArrayNode();
			seriesObjectNode.set("value", seriesValueArrayNode);
			for (int j = 0; j < newDataList.size(); j++) {
				BigDecimal value = (BigDecimal) newDataList.get(j).get("value_" + i);
				seriesValueArrayNode.add(value);
			}
		}
		return returnObjectNode;
	}

	protected ObjectNode getTwoDimensiongetRenderValue(YunContext yunContext, Component component) {
		AbstractChart abstractChart=(AbstractChart)component;
		Page page = yunContext.getPage();
		DataSourceConfig dataSourceConfig = page.getDataSourceConfigById(abstractChart.getDataSource());
		Table table = tableStore.get(dataSourceConfig.getTableName());
		List<ChartDataItemDef> dimensionList = abstractChart.getDimensionList();
		List<ChartDataItemDef> measureList = abstractChart.getMeasureList();
		List<Map<String, Object>> mapList = yunContext.getAttribute(component.getId() + "_chartdata");
		if(mapList==null ||mapList.size()==0) {
			return null;
		}
		Map<String, BigDecimal> dataMap = new HashMap<String, BigDecimal>();
		Map<String, Long> lengthMap = new HashMap<String, Long>();
		List<List<Object>> dimensionValueListList = new ArrayList<List<Object>>();
		List<Column> columnList = new ArrayList<Column>();
		for (int i = 0; i < dimensionList.size(); i++) {
			dimensionValueListList.add(new ArrayList<Object>());
			Column column = table.getColumnByColumnName(dimensionList.get(i).getField());
			columnList.add(column);
		}

		for (int i = 0; i < mapList.size(); i++) {
			Map<String, Object> map = mapList.get(i);
			String dimensionKey = getTwoDimensionKey(yunContext, abstractChart, map, dimensionValueListList);
			BigDecimal fieldValue = dataMap.get(dimensionKey);
			String measureField = measureList.get(0).getField();
			Object measureValue = map.get(measureField);
			String aggregateType = measureList.get(0).getAggregateType();
			if ("sum".equals(aggregateType)) {
				if (fieldValue == null) {
					fieldValue = new BigDecimal(0);
				}
				fieldValue = fieldValue.add(new BigDecimal(measureValue + ""));
				dataMap.put(dimensionKey, fieldValue);
			} else if ("average".equals(aggregateType)) {
				if (fieldValue == null) {
					fieldValue = new BigDecimal(0);
				}
				fieldValue = fieldValue.add(new BigDecimal(measureValue + ""));
				dataMap.put(dimensionKey, fieldValue);
				Long length = lengthMap.get(dimensionKey);
				if (length == null) {
					length = 1L;
				} else {
					length++;
				}
				lengthMap.put(dimensionKey, length);
			} else if ("count".equals(aggregateType)) {
				if (fieldValue == null) {
					fieldValue = new BigDecimal(0);
				}
				fieldValue = fieldValue.add(new BigDecimal(1));
				dataMap.put(dimensionKey, fieldValue);
			} else if ("min".equals(aggregateType)) {
				if (fieldValue == null) {
					dataMap.put(dimensionKey, new BigDecimal(measureValue + ""));
				} else if (new BigDecimal(measureValue + "").compareTo(fieldValue) < 0) {
					fieldValue = new BigDecimal(measureValue + "");
					dataMap.put(dimensionKey, fieldValue);
				}
			} else if ("max".equals(aggregateType)) {
				if (fieldValue == null) {
					dataMap.put(dimensionKey, new BigDecimal(measureValue + ""));
				} else if (new BigDecimal(measureValue + "").compareTo(fieldValue) > 0) {
					fieldValue = new BigDecimal(measureValue + "");
					dataMap.put(dimensionKey, fieldValue);
				}
			}
		}
		boolean isAverageAggregateType = "average".equals(measureList.get(0).getAggregateType());
		if (isAverageAggregateType) {
			Iterator<Map.Entry<String, BigDecimal>> it = dataMap.entrySet().iterator();
			while (it.hasNext()) {
				Map.Entry<String, BigDecimal> entry = it.next();
				long length = lengthMap.get(entry.getKey());
				if (length > 0) {
					dataMap.put(entry.getKey(), entry.getValue().divide(new BigDecimal(length)));
				}
			}
		}
		Map<String, List<SelectItem>> selectItemListMap = new HashMap<String, List<SelectItem>>();
		for (int i = 0; i < columnList.size(); i++) {
			Column column = columnList.get(i);
			if (column.getLookupInfo() != null) {
				List<SelectItem> selectItemList = null;
				if (column.getLookupInfo().getDataSourceConfig() != null) {
					Set<Object> set = new HashSet<Object>();
					set.addAll(dimensionValueListList.get(i));
					selectItemList = lookupUtil.getSelectItemList(yunContext, column.getLookupInfo(), set);
				} else {
					selectItemList = lookupUtil.getSelectItemList(yunContext, column.getLookupInfo());
				}
				selectItemListMap.put(column.getColumnName(), selectItemList);
			}
		}
		
		for(int i=0;i<dimensionList.size();i++) {
			ChartDataItemDef chartDataItemDef=dimensionList.get(i);
			String orderBy=chartDataItemDef.getOrderType();
			Column column = columnList.get(i);
			if(!StringUtils.isEmpty(orderBy)) {
				List<Object> dimensionValueList = dimensionValueListList.get(i);
				List<SelectItem> selectItemList=selectItemListMap.get(column.getColumnName());
				if(selectItemList!=null) {
					List<Map<String,Object>> newMapList=new ArrayList<Map<String,Object>>();
					for(int j=0;j<dimensionValueList.size();j++) {
						Map<String,Object> newMap=new HashMap<String,Object>();
						newMapList.add(newMap);
						newMap.put("value", dimensionValueList.get(j));
						for(int k=0;k<selectItemList.size();k++) {
							if(selectItemList.get(k).getValue().equals(dimensionValueList.get(j))) {
								newMap.put("label", selectItemList.get(k).getName());
								break;
							}
						}
					}
					if("asc".equals(orderBy)) {
						newMapList.sort(new Comparator<Map<String,Object>>(){

							@Override
							public int compare(Map<String, Object> o1, Map<String, Object> o2) {
								// TODO Auto-generated method stub
								String label1=(String)o1.get("label");
								String label2=(String)o2.get("label");
								return label1.compareTo(label2);
							}
						});
					}else if("desc".equals(orderBy)) {
						newMapList.sort(new Comparator<Map<String,Object>>(){

							@Override
							public int compare(Map<String, Object> o1, Map<String, Object> o2) {
								// TODO Auto-generated method stub
								String label1=(String)o1.get("label");
								String label2=(String)o2.get("label");
								return label2.compareTo(label1);
							}
						});
					}
					List<Object> newDimensionValueList=new ArrayList<Object>();
					for(int j=0;j<newMapList.size();j++) {
						newDimensionValueList.add(newMapList.get(j).get("value"));
					}
					dimensionValueListList.set(i, newDimensionValueList);
				}else {
					if("asc".equals(orderBy)) {
						dimensionValueList.sort(new Comparator<Object>(){

							@Override
							public int compare(Object o1, Object o2) {
								// TODO Auto-generated method stub
								return ((String)o1).compareTo((String)o2);
							}
						});
					}else if("desc".equals(orderBy)) {
						dimensionValueList.sort(new Comparator<Object>(){

							@Override
							public int compare(Object o1, Object o2) {
								// TODO Auto-generated method stub
								return ((String)o2).compareTo((String)o1);
							}
						});
					}
				}
			}
		}
		ObjectNode returnObjectNode = objectMapper.createObjectNode();
		ArrayNode categoryArrayNode = objectMapper.createArrayNode();
		List<Object> dimensionValueList = dimensionValueListList.get(0);
		int topN=abstractChart.getTopN();
		if(topN>0 && dimensionValueList.size()>topN) {
			int c=dimensionValueList.size()-topN;
			for(int i=0;i<c;i++) {
				dimensionValueList.remove(dimensionValueList.size()-1);
			}
		}
		List<SelectItem> selectItemList0=selectItemListMap.get(columnList.get(0).getColumnName());
		for(int i=0;i<dimensionValueList.size();i++) {
			if(selectItemList0!=null) {
				for(int j=0;j<selectItemList0.size();j++) {
					if(selectItemList0.get(j).getValue().equals(dimensionValueList.get(i))) {
						categoryArrayNode.add(selectItemList0.get(j).getName());
						break;
					}
				}
			}else {
				categoryArrayNode.add((String)dimensionValueList.get(i));
			}
		}
		returnObjectNode.set("category", categoryArrayNode);
		ArrayNode seriesArrayNode = objectMapper.createArrayNode();
		returnObjectNode.set("series", seriesArrayNode);
		
		List<Object> dimension0ValueList = dimensionValueListList.get(0);
		List<Object> dimension1ValueList = dimensionValueListList.get(1);
		List<SelectItem> selectItemList1=selectItemListMap.get(columnList.get(1).getColumnName());
		for(int i=0;i<dimension1ValueList.size();i++) {
			ObjectNode seriesObjectNode = objectMapper.createObjectNode();
			seriesArrayNode.add(seriesObjectNode);
			if(selectItemList1==null) {
				seriesObjectNode.put("name",(String)dimension1ValueList.get(i));
			}else {
				for(int j=0;j<selectItemList1.size();j++) {
					if(selectItemList1.get(j).getValue().equals(dimension1ValueList.get(i))) {
						seriesObjectNode.put("name",selectItemList1.get(j).getName());
						break;
					}
				}
			}
			ArrayNode seriesValueArrayNode = objectMapper.createArrayNode();
			seriesObjectNode.set("value", seriesValueArrayNode);
			for(int j=0;j<dimension0ValueList.size();j++) {
				BigDecimal value=dataMap.get(dimension0ValueList.get(j)+"::"+dimension1ValueList.get(i));
				if(value==null) {
					value=new BigDecimal(0);
				}
				seriesValueArrayNode.add(value);
			}
		}
		return returnObjectNode;
	}
	
	protected String getOneDimensionKey(YunContext yunContext,AbstractChart abstractChart,Map<String, Object> dataMap,List<Object> dimensionValueList) {
		List<ChartDataItemDef> dimensionList = abstractChart.getDimensionList();
		String dimensionField = dimensionList.get(0).getField();
		String fieldExtra = dimensionList.get(0).getFieldExtra();
		Object dimensionValue = dataMap.get(dimensionField);
		if (!StringUtils.isEmpty(fieldExtra)) {
			Date dateValue = (Date) dimensionValue;
			if ("year".equals(fieldExtra)) {
				dimensionValue = new SimpleDateFormat("yyyy年").format(dateValue);
			} else if ("quarter".equals(fieldExtra)) {
				Calendar calendar = Calendar.getInstance();
				calendar.setTime(dateValue);
				StringBuilder dimensionValueBuilder = new StringBuilder();
				int year = calendar.get(Calendar.YEAR);
				dimensionValueBuilder.append(year);
				dimensionValueBuilder.append("年");
				int month = calendar.get(Calendar.MONTH);
				if (month >= 0 && month <= 2) {
					dimensionValueBuilder.append("第一季度");
				} else if (month >= 3 && month <= 5) {
					dimensionValueBuilder.append("第二季度");
				} else if (month >= 6 && month <= 8) {
					dimensionValueBuilder.append("第三季度");
				} else if (month >= 9 && month <= 11) {
					dimensionValueBuilder.append("第四季度");
				}
				dimensionValue = dimensionValueBuilder.toString();
			} else if ("month".equals(fieldExtra)) {
				dimensionValue = new SimpleDateFormat("yyyy年MM月").format(dateValue);
			} else if ("day".equals(fieldExtra)) {
				dimensionValue = new SimpleDateFormat("yyyy-MM-dd").format(dateValue);
			}
		}
		if (!dimensionValueList.contains(dimensionValue)) {
			dimensionValueList.add(dimensionValue);
		}
		String dimensionKey = dimensionValue + "";
		return dimensionKey;
	}
	
	protected String getTwoDimensionKey(YunContext yunContext,AbstractChart abstractChart,Map<String, Object> dataMap,List<List<Object>> dimensionValueListList) {
		List<ChartDataItemDef> dimensionList = abstractChart.getDimensionList();
		StringBuilder dimensionKeyBuilder = new StringBuilder();
		for (int j = 0; j < dimensionList.size(); j++) {
			String dimensionField = dimensionList.get(j).getField();
			if (j > 0) {
				dimensionKeyBuilder.append("::");
			}
			Object dimensionValue = dataMap.get(dimensionField);
			String fieldExtra = dimensionList.get(j).getFieldExtra();
			if (!StringUtils.isEmpty(fieldExtra)) {
				Date dateValue = (Date) dimensionValue;
				if ("year".equals(fieldExtra)) {
					dimensionValue = new SimpleDateFormat("yyyy年").format(dateValue);
				} else if ("quarter".equals(fieldExtra)) {
					Calendar calendar = Calendar.getInstance();
					calendar.setTime(dateValue);
					StringBuilder dimensionValueBuilder = new StringBuilder();
					int year = calendar.get(Calendar.YEAR);
					dimensionValueBuilder.append(year);
					dimensionValueBuilder.append("年");
					int month = calendar.get(Calendar.MONTH);
					if (month >= 0 && month <= 2) {
						dimensionValueBuilder.append("第一季度");
					} else if (month >= 3 && month <= 5) {
						dimensionValueBuilder.append("第二季度");
					} else if (month >= 6 && month <= 8) {
						dimensionValueBuilder.append("第三季度");
					} else if (month >= 9 && month <= 11) {
						dimensionValueBuilder.append("第四季度");
					}
					dimensionValue = dimensionValueBuilder.toString();
				} else if ("month".equals(fieldExtra)) {
					dimensionValue = new SimpleDateFormat("yyyy年MM月").format(dateValue);
				} else if ("day".equals(fieldExtra)) {
					dimensionValue = new SimpleDateFormat("yyyy-MM-dd").format(dateValue);
				}
			}
			dimensionKeyBuilder.append(dimensionValue);
			List<Object> dimensionValueList = dimensionValueListList.get(j);
			if (!dimensionValueList.contains(dimensionValue)) {
				dimensionValueList.add(dimensionValue);
			}
		}
		return dimensionKeyBuilder.toString();
	}
}
